#coding=utf-8
import random
import yaml
from stockdb import *

def pprice(p):
    print p.td.date, p.close, p.lowest, p.change, p.volume, p.trade_rate

def rp(cs):
    c = random.choice(cs)
    s = sess.query(Stock).filter_by(code=c).one()
    print s.code,s.name
    if s.today:pprice(s.today.price)


class ColAttr(object):

    boolean_attrs = ['is_percent', 'is_colored']
    def __init__(self, uname, **attrs):
        self.uname = name
        self.attrs = attrs
        
        #default value
        for a in self.boolean_attrs:
            self[a] = False
    
    def get(self, key):
        return self.attrs.get(key)
        
    def __setitem__(self, k, v):
        self.attrs[k] = v
        
    def dump(self, f):
        batt
        if not self.get('is_percent'):
            self.attrs['is_percent'] = False
        if not self
            
class ColAttrList(list):
    
    def search_by_uname(self, name):
        
        for ca in self:
            if ca.uname == name
                return ca
                
